﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using ucApi;

public partial class Admin_Admin_Passport : Admin, IRequiresSessionState
{
    private Pagination _p;
    private UserBll _user;
    private AccountDetailsBll _payment = null;
    private string whereStr = "";
    private string OrderByStr = "";
    private string linkHead = "";
    private IDbDataParameter[] param;
    private ArrayList al = new ArrayList();
    private bool CanGetQuestString = true;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected Pagination m_p
    {
        get
        {
            Pagination p;
            if (this._p == null)
            {
                this._p = new Pagination();
                this._p.SQL_LeftJoinTable = "HL_Group";
                this._p.SQL_LeftJoinField = "GroupName";
                this._p.SQL_JoinField = "GroupID";
                this._p.SQL_JoinField2 = "GroupID";
                this._p.P_Object = "位会员";
                p = this._p;
            }
            else
            {
                p = this._p;
            }
            return p;
        }
    }
    protected UserBll m_User
    {
        get
        {
            UserBll user;
            if (this._user == null)
            {
                this._user = new UserBll(this.conn);
                user = this._user;
            }
            else
            {
                user = this._user;
            }
            return user;
        }
    }
    protected AccountDetailsBll m_payment
    {
        get
        {
            AccountDetailsBll payment;
            if (this._payment == null)
            {
                this._payment = new AccountDetailsBll(this.conn);
                payment = this._payment;
            }
            else
            {
                payment = this._payment;
            }
            return payment;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(6))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "PassPort");
            base.WriteRightErrMsg();
        }
        if (!base.IsPostBack)
        {
            this.BindAllMember();
            this.BindList();
            if (base.Request.QueryString["pageindex"] != null)
            {
                base.Response.Write(base.Request.QueryString["pageindex"].ToString());
                this.BindGroupMember();
            }
        }
    }
    public void BindAllMember()
    {
        this.DDL_MemberTypeSearch.DataTextField = "GroupName";
        this.DDL_MemberTypeSearch.DataValueField = "GroupID";
        this.DDL_MemberTypeSearch.DataSource = this.conn.GetDataSet("select GroupName,GroupID from HL_Group");
        this.DDL_MemberTypeSearch.DataBind();
        this.DDL_MemberTypeSearch.Items.Insert(0, "所有的会员组");
        this.DDL_MemberTypeSearch.Items[0].Value = "0";
        this.DDL_MemberTypeSearch.Items[0].Selected = true;
    }
    protected void BindList()
    {
        this.GetQuestString();
        int num = Fetch.GetID("page");
        if (num == 0)
        {
            num = 1;
        }
        int pageSize = this.GridView1.PageSize;
        if (this.al.Count > 0)
        {
            this.param = new IDbDataParameter[this.al.Count];
            this.al.CopyTo(this.param, 0);
        }
        if (this.param != null)
        {
            this.GridView1.DataSource = this.m_p.GetDataTable("HL_User", num, pageSize, "UserID", this.whereStr, this.OrderByStr, this.conn, this.param);
        }
        else
        {
            this.GridView1.DataSource = this.m_p.GetDataTable("HL_User", num, pageSize, "UserID", this.whereStr, this.OrderByStr, this.conn, null);
        }
        this.GridView1.DataBind();
        this.m_p.P_LinkHead = this.linkHead;
        this.PagePanel.Text = this.m_p.ShowPagePanel();
    }
    protected void GetQuestString()
    {
        string text = Fetch.Get("ByType");
        if (text != string.Empty && this.CanGetQuestString)
        {
            this.SelectUserType.SelectedValue = text;
        }
        else
        {
            text = this.SelectUserType.SelectedValue;
        }
        if (text != "all")
        {
            string text2 = text;
            if (text2 != null)
            {
                if (!(text2 == "24hourlogin"))
                {
                    if (!(text2 == "24hourreg"))
                    {
                        if (!(text2 == "loginmost"))
                        {
                            if (text2 == "balanceasc")
                            {
                                this.OrderByStr = " Balance Desc ";
                            }
                        }
                        else
                        {
                            this.OrderByStr = " LoginTimes Desc,HL_User.UserID Desc ";
                        }
                    }
                    else
                    {
                        this.whereStr += "and datediff(hh,RegTime,getdate())<=24 ";
                    }
                }
                else
                {
                    this.whereStr += "and datediff(hh,LastLoginTime,getdate())<=24 ";
                }
            }
            this.linkHead = "&ByType=" + text;
        }
        string text3 = Fetch.Get("ByName");
        if (text3 != string.Empty && this.CanGetQuestString)
        {
            text3 = base.Server.UrlDecode(text3);
            this.SearchUserTextBox.Text = text3;
        }
        else
        {
            text3 = this.SearchUserTextBox.Text;
        }
        if (text3 != string.Empty)
        {
            if (this.DDL_SearchType.SelectedValue == "1")
            {
                this.whereStr += "and UserName like '%'+ @UserName + '%' ";
            }
            else
            {
                this.whereStr += "and UserName=@UserName ";
            }
            this.al.Add(this.conn.CreateParameter("@UserName", DbType.String, text3));
            this.linkHead = "&ByName=" + base.Server.UrlEncode(text3);
        }
        int iD = Fetch.GetID("gid");
        if (iD > 0 && this.CanGetQuestString)
        {
            object obj = this.whereStr;
            this.whereStr = string.Concat(new object[]
			{
				obj,
				"and HL_User.GroupID = ",
				iD,
				" "
			});
            this.linkHead = "&gid=" + iD;
        }
        if (this.whereStr != string.Empty)
        {
            this.whereStr = "and" + this.whereStr;
            this.whereStr = this.whereStr.Replace("andand", "where");
        }
    }
    protected void UserButtonOnCommon(object sender, CommandEventArgs e)
    {
        string text = "";
        string text2 = "";
        if (base.Request["chkSelect"] != null && base.Request["chkSelect"] != "")
        {
            text = base.Request["chkSelect"];
        }
        if (text != "")
        {
            AppSetings appSetings = new AppSetings();
            if (appSetings.GetConfig("UC_ONorOFF") == "ON")
            {
                string[] array = text.Split(new char[]
				{
					','
				});
                for (int i = 0; i < array.Length; i++)
                {
                    Func.uc_user_delete(array[i]);
                }
            }
            this.m_User.AdminUser(text, e.CommandName.ToString());
            string text3 = e.CommandName.ToString();
            if (text3 != "Delete")
            {
                text3 = "Check";
            }
            base.WriteLog(text3, Language.GetAdminMsg("Log/ObjectID", text.ToString()), "PassPort");
            if (e.CommandName.ToString() == "Delete" && this.config["HLIntegration"].ToString() == "1")
            {
                IDataReader reader = this.conn.GetReader("Select UserName From [HL_User] Where UserID in (" + text + ")");
                while (reader.Read())
                {
                    text2 = text2 + reader["UserName"] + ",";
                }
                reader.Close();
                reader.Dispose();
                if (text2 != "")
                {
                    text2 = text2.Remove(text2.Length - 1);
                }
                new Integrate(this.conn)
                {
                    UserName = text2,
                    ComeUrl = "admin_passport.aspx",
                    sendEnd = "<script>alert('" + Language.GetAdminMsg("PassPort/SynDelete") + "');location.href='{#GoUrl#}'</script>"
                }.Send("Delete", text2, "", "", "", "", 0, "", "");
            }
        }
        this.CanGetQuestString = false;
        this.BindList();
    }
    protected void Delete_OnClick(object sender, CommandEventArgs e)
    {
        try
        {
            Convert.ToInt32(e.CommandName.ToString());
        }
        catch
        {
            this.WriteErrMsg("", Language.GetAdminMsg("Common/ParamErr"), "");
        }
        string text = e.CommandName.ToString();
        Func.uc_user_delete(text);
        this.m_User.AdminUser(text, "Delete");
        base.WriteLog("Delete", Language.GetAdminMsg("Log/ObjectID", text.ToString()), "PassPort");
        if (this.config["HLIntegration"].ToString() == "1")
        {
            string userName = "";
            IDataReader reader = this.conn.GetReader("Select UserName From [HL_User] Where UserID=" + text);
            if (reader.Read())
            {
                userName = (string)reader["UserName"];
            }
            else
            {
                this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "");
            }
            new Integrate(this.conn)
            {
                ComeUrl = "admin_passport.aspx",
                sendEnd = "<script>alert('" + Language.GetAdminMsg("PassPort/SynDelete") + "');location.href='{#GoUrl#}'</script>"
            }.Send("Delete", userName, "", "", "", "", 0, "", "");
        }
        this.CanGetQuestString = false;
        this.BindList();
    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {
        this.CanGetQuestString = false;
        this.SelectUserType.SelectedValue = "all";
        this.BindList();
    }
    protected void SelectUserType_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.CanGetQuestString = false;
        this.SearchUserTextBox.Text = "";
        this.BindList();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            Label label = (Label)e.Row.FindControl("labelIsLocked");
            if (label.Text == "1")
            {
                label.Text = "锁定";
            }
            else
            {
                label.Text = "正常";
            }
        }
    }
    protected void DDL_MemberTypeSearch_SelectedIndexChanged(object sender, EventArgs e)
    {
        CurrPageLinks currPageLinks = new CurrPageLinks();
        int page = 1;
        if (base.Request.QueryString["pageindex"] != null)
        {
            page = int.Parse(base.Request.QueryString["pageindex"].ToString());
        }
        string text = "";
        string str = "";
        if (this.DDL_MemberTypeSearch.SelectedValue != "0")
        {
            text = " where a.GroupID=" + int.Parse(this.DDL_MemberTypeSearch.SelectedValue) + " and ";
            str = " where a.GroupID=" + int.Parse(this.DDL_MemberTypeSearch.SelectedValue) + " ";
        }
        int num = this.conn.ExecuteCount("select count(*) from HL_User as a " + str);
        int pageSize = num / 15;
        if (text == "")
        {
            text = " where ";
        }
        this.GridView1.DataSource = this.conn.GetDataSet("select top 15 * from HL_User as a,HL_Group as b " + text + "  a.GroupID=b.GroupID");
        this.GridView1.DataBind();
        this.PagePanel.Text = currPageLinks.CurrPageLink(page, pageSize, num, "个会员", "Admin_Passport.aspx?selectGroup=" + this.DDL_MemberTypeSearch.SelectedValue + "&pageindex");
    }
    public void BindGroupMember()
    {
        CurrPageLinks currPageLinks = new CurrPageLinks();
        int pCount = this.conn.ExecuteCount("select count(*) from HL_User");
        int num = int.Parse(base.Request.QueryString["pageindex"].ToString());
        int num2 = int.Parse(base.Request.QueryString["selectGroup"].ToString());
        this.DDL_MemberTypeSearch.SelectedValue = num2.ToString();
        int num3 = 15 * (num - 1);
        string text;
        if (num == 1)
        {
            text = "";
        }
        else
        {
            text = string.Concat(new object[]
			{
				" a.UserID not in(select top ",
				num3,
				" UserID from HL_User where GroupID=",
				num2,
				") and"
			});
        }
        this.GridView1.DataSource = this.conn.GetDataSet(string.Concat(new object[]
		{
			"select top 15 * from HL_User as a,HL_Group as b where ",
			text,
			" a.GroupID=",
			num2,
			" and a.GroupID=b.GroupID"
		}));
        this.GridView1.DataBind();
        this.PagePanel.Text = currPageLinks.CurrPageLink(num, 15, pCount, "个会员", "Admin_Passport.aspx?selectGroup=" + this.DDL_MemberTypeSearch.SelectedValue + "&pageindex");
    }
    protected string UserLogUrl(object userid)
    {
        return string.Format("UserLogin.aspx?UserID={0}&login1={1}&login2={2}", userid, userid.IsNull(new object[0]).Encrypt(), DateTime.Now.IsNull(new object[0]).Encrypt());
    }
}
